package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhPartsQrcode;
import com.ruoyi.zsyh.service.IZsyhPartsQrcodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二维码记录Controller
 * 
 * @author yuexl
 * @date 2022-01-09
 */
@Controller
@RequestMapping("/zsyh/partsQrcode")
public class ZsyhPartsQrcodeController extends BaseController
{
    private String prefix = "zsyh/partsQrcode";

    @Autowired
    private IZsyhPartsQrcodeService zsyhPartsQrcodeService;

    @RequiresPermissions("zsyh:partsQrcode:view")
    @GetMapping()
    public String partsQrcode()
    {
        return prefix + "/partsQrcode";
    }

    /**
     * 查询二维码记录列表
     */
    @RequiresPermissions("zsyh:partsQrcode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhPartsQrcode zsyhPartsQrcode)
    {
        startPage();
        List<ZsyhPartsQrcode> list = zsyhPartsQrcodeService.selectZsyhPartsQrcodeList(zsyhPartsQrcode);
        return getDataTable(list);
    }

    /**
     * 导出二维码记录列表
     */
    @RequiresPermissions("zsyh:partsQrcode:export")
    @Log(title = "二维码记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhPartsQrcode zsyhPartsQrcode)
    {
        List<ZsyhPartsQrcode> list = zsyhPartsQrcodeService.selectZsyhPartsQrcodeList(zsyhPartsQrcode);
        ExcelUtil<ZsyhPartsQrcode> util = new ExcelUtil<ZsyhPartsQrcode>(ZsyhPartsQrcode.class);
        return util.exportExcel(list, "二维码记录数据");
    }

    /**
     * 新增二维码记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存二维码记录
     */
    @RequiresPermissions("zsyh:partsQrcode:add")
    @Log(title = "二维码记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhPartsQrcode zsyhPartsQrcode)
    {
        return toAjax(zsyhPartsQrcodeService.insertZsyhPartsQrcode(zsyhPartsQrcode));
    }

    /**
     * 修改二维码记录
     */
    @GetMapping("/edit/{qrcodeId}")
    public String edit(@PathVariable("qrcodeId") String qrcodeId, ModelMap mmap)
    {
        ZsyhPartsQrcode zsyhPartsQrcode = zsyhPartsQrcodeService.selectZsyhPartsQrcodeById(qrcodeId);
        mmap.put("zsyhPartsQrcode", zsyhPartsQrcode);
        return prefix + "/edit";
    }

    /**
     * 修改保存二维码记录
     */
    @RequiresPermissions("zsyh:partsQrcode:edit")
    @Log(title = "二维码记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhPartsQrcode zsyhPartsQrcode)
    {
        return toAjax(zsyhPartsQrcodeService.updateZsyhPartsQrcode(zsyhPartsQrcode));
    }

    /**
     * 删除二维码记录
     */
    @RequiresPermissions("zsyh:partsQrcode:remove")
    @Log(title = "二维码记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhPartsQrcodeService.deleteZsyhPartsQrcodeByIds(ids));
    }
}
